package com.lanou3g.baidumusic.main.musicfragment.videofragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou3g.baidumusic.R;
import com.squareup.picasso.Picasso;

/**
 * Created by dllo on 17/3/21.
 */

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder> {

    private Context context ;
    private VideoBean videoBean ;
    private VideoHolder videoHolder ;

    public void setVideoBean(VideoBean videoBean){
        this.videoBean = videoBean ;
        notifyDataSetChanged();
    }

    public VideoAdapter(Context context) {
        this.context = context;
    }

    @Override
    public VideoHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_fragment_video , parent , false);

        videoHolder = new VideoHolder(view);

        return videoHolder;
    }

    @Override
    public void onBindViewHolder(VideoHolder holder, int position) {


        holder.titleTv.setText(videoBean.getResult().getMv_list().get(position).getTitle());
        holder.nameTv.setText(videoBean.getResult().getMv_list().get(position).getArtist());
        Picasso.with(context).load(videoBean.getResult().getMv_list().get(position).getThumbnail()).into(holder.imageView);

        if(position == getItemCount()-1){
            holder.blankTv.setVisibility(View.VISIBLE);
            Log.d("ListFragme ntAdapter", "blankTv");
        }
    }

    @Override
    public int getItemCount() {

        if (null == videoBean){
            return 0 ;
        }
        if (null == videoBean.getResult()){
            return 0 ;
        }

        return videoBean.getResult() != null && videoBean.getResult().getMv_list().size() > 0 ? videoBean.getResult().getMv_list().size() : 0;
    }



    public class VideoHolder extends RecyclerView.ViewHolder{

        private TextView nameTv , titleTv ,blankTv;
        private ImageView imageView ;

        public VideoHolder(View itemView) {
            super(itemView);

            titleTv = (TextView) itemView.findViewById(R.id.item_fragment_video_title);
            nameTv = (TextView) itemView.findViewById(R.id.item_fragment_video_name);
            imageView = (ImageView) itemView.findViewById(R.id.item_fragment_video_iv);

            blankTv = (TextView) itemView.findViewById(R.id.item_fragment_video_blank_tv);
        }
    }

}
